package com.soul.server.controller;

import com.soul.model.db.Settings;
import com.soul.model.vo.PageResult;
import com.soul.model.vo.SettingsVo;
import com.soul.model.vo.UserInfoVo;
import com.soul.model.vo.UserInfoVoAge;
import com.soul.server.server.SettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author mdoya
 * @version 1.0
 * @description: 通用设置控制层
 */
@Slf4j
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     *  用户通用设置 - 读取
     * @return
     */
    @RequestMapping(value = "/settings",method = RequestMethod.GET)
    public SettingsVo findByUserSettings(){
        log.info("用户通用设置 - 读取");
        return settingsService.findByUserSettings();
    }

    /**
     *  设置陌生人问题 - 保存
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity UpdateUserQuestions(@RequestBody Map<String,String> params){
        String content = params.get("content");
        log.info("设置陌生人问题 - 保存:{}",content);
        settingsService.UpdateUserQuestions(content);
        return ResponseEntity.ok(null);
    }

    /**
     *  通知设置 - 保存(更新)
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notificationsSetting(@RequestBody Settings settings){
        log.info("通知设置 - 保存(更新):{}",settings);
        settingsService.notificationsSetting(settings);
        return ResponseEntity.ok(null);
    }

    /**
     *  黑名单 - 翻页列表
     * @param page 页码
     * @param pagesize 当前页条数
     */
    @GetMapping("/blacklist")
    public ResponseEntity findBlacklist(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        log.info("黑名单 - 翻页列表  页码:{}， 当前条数:{}",page,pagesize);
        PageResult pageResult = settingsService.findBlacklist(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     *  黑名单 - 移除
     * @param uid 黑名单用户id
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackByUid(@PathVariable("uid") Long uid){
        log.info("黑名单用户id:{}",uid);
        settingsService.deleteBlackByUid(uid);
        return ResponseEntity.ok(null);
    }

    /**
     *  更新手机号码获取验证码
     */
    @PostMapping("/phone/sendVerificationCode")
    public ResponseEntity sendVerificationCode(){
        log.info("更新手机号码获取验证码");
        settingsService.sendVerificationCode();
        return ResponseEntity.ok(null);
    }

    /**
     *  更新手机号码校验验证码
     */
    @PostMapping("/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String,String> params){
        log.info("更新手机号码校验验证码:{}",params);
        return ResponseEntity.ok(settingsService.checkVerificationCode(params.get("verificationCode")));
    }

    /**
     *  更新手机号码
     */
    @PostMapping("/phone")
    public ResponseEntity updatePhone(@RequestBody Map<String,String> params){
        log.info("更新手机号码:{}",params);
        settingsService.updatePhone(params.get("phone"));
        return ResponseEntity.ok(null);
    }
}
